package io.nanfeng.coroutine

import kotlinx.coroutines.*
import kotlinx.coroutines.reactor.flux
import kotlinx.coroutines.reactor.mono


fun main(args: Array<String>) = runBlocking<Unit> {
    val job = launch {

        launch {
            println("World")
            delay(1400)


            withTimeout(1000) {
                awaitCancellation()
                println("Hello")
                delay(1400)
            }
            for (i in 1..10) {
                launch {
                    println("创建新的协程 ${this.coroutineContext}")
                    delay(7000)
                }
            }
            async {
                delay(2000)
                error("出错了")
            }

        }

        mono {

        }

        flux<String>{
            this.send("as")
        }.collectMap {

        }
        delay(5000)

        println("Done")
    }

    println("Hello")
    delay(2000)
}